import axios from "axios";
import cookies from "@/utils/cookies.js";

const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 20000,
});

request.interceptors.request.use(
  (config) => {
    if (cookies.getToken()) {
      config.headers["authorization"] = cookies.getToken();
    }
    config.timeout = 20000; // 20秒
    return config;
  },
  (error) => {
    return Promise.reject("请求错误" + error);
    // this.$message.warning("请求错误！");
    // console.log("请求错误！");
    // return;
  }
);

request.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (error) => {
    return Promise.reject("响应错误！" + error);
    // this.$message.warning("请求错误！");
    // console.log("请求错误！");
    // return;
  }
);

export default request;
